<template>
  <div class="text_list_box">
    <el-table
      ref="tableRef"
      :data="tableData"
      height="450"
      max-height="550"
      tooltip-effect="light"
      class="table_box"
      header-row-class-name="table_header_title"
    >
      <el-table-column
        width="50px"
        align="center"
      >
        <template #default="scope">
          <div style="display: flex; align-items: center">
            <el-checkbox
              v-model="scope.row.isCheck"
              @change="chooseText(scope.row)"
            ></el-checkbox>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="标题"
        width="200"
        align="'center'"
      >
        <template #default="scope">
          <div class="line3">{{scope.row.title}}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="内容"
        align="'center'"
      >
        <template #default="scope">
          <div class="line3">{{scope.row.content}}</div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive, watch, computed } from 'vue'

const props = defineProps(['baseList'])
const emit = defineEmits(['getData'])
let textArr = []
const chooseText = (item: any) => {
  if (item.isCheck) {
    textArr.push(item)
    if (textArr.length > 1) {
      let index = tableData.value.findIndex((it: any) => it.id === textArr[0].id)
      tableData.value[index].isCheck = false
      textArr.splice(0, 1)
    }
    emit('getData', {
      type: 1,
      typeStr: 'text',
      data: textArr
    })
  }
}
const tableData = computed(() => {
  let arr: any[] = []
  textArr = []
  if (props?.baseList?.length > 0) {
    props?.baseList.forEach((item: any) => {
      item.isCheck = false
      arr.push(item)
    })
  }
  return arr
})
</script>

<style lang="scss" scoped>
.text_list_box {
  width: 100%;
  .line3 {
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    word-break: break-all;
  }
  :deep .el-checkbox__inner {
    border-radius: 50%;
  }
}
</style>
<style lang="scss">
.text_list_box {
  .el-table--scrollable-y ::-webkit-scrollbar {
    display: none;
  }
  .table_header_title {
    th.el-table__cell {
      background: #f9f9f9;
      padding: 10px 0;
    }
  }
}
</style>
